package com.coda.controller;

import com.coda.entity.SystemPost;
import com.coda.result.PageResult;
import com.coda.result.Result;
import com.coda.service.SystemPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("//admin/system/post")
@Api(tags = "后台用户岗位管理")
public class SystemPostController {
    @Autowired
    private SystemPostService systemPostService;

    /**
     * 分页查询岗位信息
     */
    @GetMapping("/page")
    @ApiOperation("分页查询岗位信息")
    public Result<PageResult> getPageList(@RequestParam Integer current,
                                          @RequestParam Integer size){
        PageResult pageResult = systemPostService.getPageList(current,size);
        return Result.ok(pageResult);
    }
    /**
     * 保存或更新岗位信息
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperation("保存或更新岗位信息")
    public Result saveOrUpdate(@RequestBody SystemPost systemPost){
        systemPostService.saveOrUpdate(systemPost);
        return Result.ok();
    }
    /**
     * 根据id查询岗位信息
     */
    @GetMapping("/getById")
    @ApiOperation("根据id查询岗位信息")
    public Result<SystemPost> getPostById(Long id){
        SystemPost systemPost = systemPostService.getPostById(id);
        return Result.ok(systemPost);
    }
    /**
     * 根据id修改岗位状态
     */
    @PostMapping("/updateStatusByPostId")
    @ApiOperation("根据id修改岗位状态")
    public Result updateStatus(@RequestParam Long id,@RequestParam Integer status){
        systemPostService.updateStatus(id,status);
        return Result.ok();
    }
    /**
     * 根据id删除岗位信息
     */
    @DeleteMapping("/deleteById")
    @ApiOperation("根据ID删除岗位信息")
    public Result deleteById(Long id){
        systemPostService.deleteById(id);
        return Result.ok();
    }
    /**
     * 获取全部岗位列表
     */
    @GetMapping("/list")
    @ApiOperation("获取全部岗位列表")
    public Result<List<SystemPost>> getList(){
        List<SystemPost> systemPost = systemPostService.getList();
        return Result.ok(systemPost);
    }
}
